import { service } from "@/utils/request"
import type { ListingConfirmInfo, ManagerListingQuery, UserListingQuery } from '@/interface/listing'
import qs from 'qs'


export function submitListing(data: ListingConfirmInfo) {
  return service({
    url: '/send/insertOrder',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: JSON.stringify(data)
  })
}

export function queryListingByUid(id: number | string) {
  return service({
    url: `/queryList/queryByUserId?userId=${id}`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
export function queryListingByYearMonth(data: UserListingQuery | ManagerListingQuery) {
  if('userId' in data) {
    return service({
      url: '/queryList/queryByUserIdAndYM',
      method: 'POST',
      data: qs.stringify(data)
    })
  } else {
    return service({
      url: '/queryList/queryByOfficeIdAndYM',
      method: 'POST',
      data: qs.stringify(data)
    })
  }
  
  
}

export function queryListingDetailById(id: string | number) {
  return service({
    url: `/queryList/getDetail?listId=${id}`,
    method: 'POST'
  })
}

export function queryListingByOfficeId(oid: string|number) {
  return service({
    url: `http://121.196.196.196:8182/queryList/queryByOfficeId?officeId=${oid}`,
    method: 'POST'
  })
} 
